<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    var arr  = ["张三","李四","王五",["王小二"]];
    let [name1,name2,name3,[name4]] = arr;
    console.log(name1,name2,name3,name4);


    var [a,b,c] = [1,2,3,4];
    console.log(c);
    console.log(a,b,c);

    var a = 10;
    var b = 20;

        // 交换变量
        var [b,a] = [a,b];
        console.log(a,b);


        function fn([a,b,c]){
            // console.log(arr);
            console.log(a,b,c);
            
        }

        fn([1,2,3]);




        var obj = {
            myname:"张三",
            age:20,
            height:"178cm"
        }

        var myname = obj.myname;
        var age = obj.age;
        var height = obj.height;
        console.log(myname,age,height)


        let {myname:myname1,age:myage,height:myheight} = obj;
        console.log(myname1,myage,myheight);

        var obj  = {
            name:"张三",
            age:20,
            hobby:{
                one:"篮球",
                two:"足球"
            },
            arr:[1,2,3]
        }

        // let {name:myname,age:myage,hobby:{one:myone,two:mytwo},arr:[a,b,c]} = obj;
        console.log(myname,myage,myone,mytwo,a,b,c);




        var obj = {
            myname:"张三",
            age:20,
            height:"178cm"
        }

        // 普通的解构 ，把键名和键值解构出来 ；
        // let {myname:myname,age:age,height:height} = obj;

        // 键名和键值 需要一样 ，你可以省略一个 名称和 冒号
        // let {myname,age,height:myheight} = obj;
        console.log(myname,age,myheight);




        function fn({myname,age}){  // 把对象参数 解构出来
            // console.log(obj);  
            // console.log(myname,myage)
            console.log(myname,age)
        }

        fn({myname:"张三",age:20})


        var str = "abcdefg";
        // console.log(str[3]);
        // str[3] = "1"
        // console.log(str);
    //    console.log(  str.length);
        let [a,b,c,d,e,f,g] = str;
        console.log(a,g);
</script>